<?php

namespace app\home\controller;

use app\company\service\DataService;
use library\Controller;
use think\Db;
use think\facade\Request;
use app\common\controller\Common;

/**
 * 多多
 */
class Duoduo extends Controller
{
    /**
     * 多多售后审核数据导出
     * @auth true
     * @throws \think\Exception
     * @throws \think\exception\PDOException
     */
    public function index()
    {
        if(request()->isPost()){
            $data = request()->post('data');
            $list = json_decode($data, true)['result']['items'];
            foreach ($list as &$v) {
                $v['operatorReasonCodeDesc'] = $v['operatorReasonCodeDesc'].$v['stationReasonCodeDesc'];
                $v['driverCheckStatus'] = $v['driverAuditData']['driverCheckStatus'];
                $v['appealStartTime'] = date('Y-m-d',$v['appealStartTime']/1000);
                $v['expectTime'] = date('Y-m-d',$v['expectTime']/1000);
                $v['checkLackQuantity'] = '少'.$v['checkLackQuantity'].','.$v['checkStatus'];
                $v['checkLackStatus'] = $v['checkLackStatus'];
                //站内分拣
                $v['sorting'] = "团长点少{},服务站少货{$v['stationLackCount']},服务站破碎{$v['stationDamagedCount']}";
            }
            $name = date('Y-m-d') . '售后审核';
            $head = ['门店', '商品名称', '审核发起日期', '提货日期', '司机名称', '商品属性', '单价（元）', '售后总金额',
             '团点申请售后缺货数（件）','团点应履约商品数（件）',
            //   '团点清点', '站内分拣', '最终审核缺货（件）', '最终缺货原因',
            //   '最终缺货责任方', '审核有效期', '司机核对状态','审核状态'
            ];
            //数据中对应的字段，用于读取相应数据：
            $keys = ['storeName', 'goodsName', 'appealStartTime','expectTime', 'driverName', 'goodsProperty','unitPrice', 'stationLackTotalAmount',
             'operatorConfirmLackCount', 'storeExpectQuantity',
            //   'checkLackQuantity', 'checkLackStatus', 'operatorConfirmLackCount', 'operatorReasonCodeDesc',
            // 'stationResponsibilitySideDesc','transportDate','driverCheckStatus','stationLackStatus'
            ];
            Common::export($name, $list, $head, $keys);
        }else{
            $this->fetch();
        }
        
    }
}
